import Taro, { Component } from '@tarojs/taro';
import PageLoad from '../PageLoading';
import Pdfh5 from 'pdfh5';
import 'pdfh5/css/pdfh5.css';
class Pdf extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true
    };
  }

  checkRefresh() {
    const pdf = document.getElementById('pdfList');
    console.log('pdf:', pdf);
  }
  componentDidMount() {
    const that = this;

    //实例化
    this.pdfh5 = new Pdfh5('#pdfList', {
      pdfurl: this.props.src,
      lazy: true,
      cMapUrl: 'https://unpkg.com/pdfjs-dist@2.0.943/cmaps/'
    });
    //监听完成事件
    this.pdfh5.on('complete', function (status, msg, time) {
      that.setState({
        loading: false
      });
      console.log(
        '状态：' + status + '，信息：' + msg + '，耗时：' + time + '毫秒，总页数：' + this.totalNum
      );
    });
  }

  componentWillUnmount() {
    this.pdfh5.destroy();
  }

  render() {
    return (
      <div>
        <div id="pdfList" style={{ height: '90vh' }}></div>
      </div>
    );
  }
}
export default Pdf;

//{this.state.loading ? <PageLoad /> : null}
